package com.kotlin.lib.multi.callback

typealias  Fun1 = (String) -> Unit
typealias Fun2 = (String, String) -> Unit
typealias Fun3 = (Fun1) -> Unit
typealias  Fun4 = (Fun2) -> Unit
typealias CallBack = (Fun3, Fun4) -> Unit

class MultiCallBack {
    lateinit var newCall: CallBack
    fun callBack(call: CallBack) {
        newCall = call
        println("callBack called")
    }

    var mFun: Fun1? = null

    fun setCallBack() {
        println("setCallBack invoked")
        val fun1: Fun3 = {
            mFun = it
        }

        val fun2: Fun4 = {
            it("2", "3")
        }

        newCall(fun1, fun2)
    }

    fun setCallBack2() {
        println("setCallBack2 invoked")
        mFun?.invoke("reset")
    }

    fun testCallBack() {
        callBack { fun0, fun1 ->
            fun0 {
                println("testCallBack fun0 read $it")
            }
            fun1 { v1, v2 ->
                println("testCallBack fun1 read $v1, $v2")
            }
        }

        setCallBack()
        setCallBack2()
    }
}

fun main() {
    MultiCallBack().testCallBack()
}




